package com.itheima.ArrayListTest;

import java.util.ArrayList;
import java.util.Scanner;

public class PhoneTest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Phone> list = new ArrayList<>();
        //把对象里面的数据存储到集合中
        for (int i = 0; i < 3; i++) {
            Phone p1 = new Phone();
            System.out.println("请输入品牌");
            String name = sc.next();
            System.out.println("请输入价格");
            int price = sc.nextInt();

            p1.setName(name);
            p1.setPrice(price);

            list.add(p1);
        }
        ArrayList<String> strings = lowPrice(list);
        for (int i = 0; i < strings.size(); i++) {
            System.out.println(strings.get(i));
        }

    }

    public static ArrayList<String> lowPrice(ArrayList<Phone> list){
        //创建一个集合用来存储价格低于3000的手机型号
        ArrayList<String> list1 = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            int price = list.get(i).getPrice();
            if(price<3000){
                list1.add(list.get(i).getName());
            }
        }
        return list1;
    }
}
